package com.example.demo.service;

import com.example.demo.mapper.UserMapper;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional
public class JwtUserDetailService implements UserDetailsService {
    @Resource
    private UserMapper userMapper;
    @Override
        public UserDetails loadUserByUsername(String id) throws UsernameNotFoundException {
            if(userMapper.findUserByID(id) == null)
                throw new UsernameNotFoundException("User: '" + id + "' not found.");
            return userMapper.findUserByID(id);
    }

}
